package com.icbc.test;

import java.util.Arrays;
import java.util.Random;

public class J_Grid15 {
	
	int[][] m_board;
	public J_Grid15(){
		m_board = new int[5][5];
	}
	
	public static void main(String[] args) {
		J_Grid15 j = new J_Grid15();
		//j.mb_showGrid();
		//j.sum(j.getNum(),65,3,j.getNum().length - 1,5);
		System.out.println("abc".contains(""));
		
		//int[] ints = j.diguiSum(j.getNum(), 65,5);
		//j.printcache(ints);
	}
	
	public int[] diguiSum(int[] array,int sum,int num) {
		
		for (int i = num - 1; i < array.length; i++) {
			int[] cache = new int[i + 1];
			int ceng = -1;
			int cengQuit = i;
			int startPiont = 0;
			int[] cir = cir(ceng, cengQuit, startPiont, array, cache, sum);
			return cir;
		}
		return null;
	}
	
	// 递归求结果
	public int[] cir(int ceng, int cengQuit, int startPiont, int[] array, int[] cache, int sum) {
		ceng++;
		for (int i = startPiont; i < array.length; i++) {
			cache[ceng] = array[i];
			if (ceng == cengQuit) {
				if (getSum(cache) == sum) {
					printcache(cache);
					//return cache;
				}
				if (getSum(cache) > sum) {
					break;
				}
			}
			if (ceng < cengQuit) {
				startPiont = i + 1;
				cir(ceng, cengQuit, startPiont, array, cache,sum);
			}
		}
		return null;
	}
	
	// 获取组合数字之和
	public int getSum(int[] cache) {
		int sum = 0;
		for (int i = 0; i < cache.length; i++) {
			sum = sum + cache[i];
		}
		return sum;
	}
	
	// 打印组合的可能
	public void printcache(int[] cache) {
		for (int i = 0; i < cache.length; i++) {
			System.out.print(cache[i] + ",");
		}
		System.out.println();
	}
	
	public void mb_showGrid(){
		int i;
		do {
			getGridData();
		} while (!lin());
		print();
	}
	
	private int[] getNum(){
		int[] num = new int[m_board.length * m_board.length];
		for (int b = 0 ; b < m_board.length ; b ++) {
			for (int a = 0 ; a < m_board.length ; a ++){
				num[b * m_board.length + a] = b * m_board.length + a + 1;
			}
		}
		return num;
	}
	
	public void sum(int[] num,int sum,int start,int end,int s){
		//int sum_pre = 0;
		//int end = num.length - 1;
		if (s == 2) {
			while (start < end) {
				if (num[start] + num[end] > sum) {
					end--;
				} else if (num[start] + num[end] < sum) {
					start++;
				} else {
					System.out.print(num[end]);
					System.out.print(num[start] + " ");
					start++;
				}
			}
			System.out.println();
		} else {
			
			int ss = 0;
			for (int a = s - 3 ; a >= 0 ; a --){
				ss += num[a];
			}
			ss += num[start];
			if (ss + num[end] > sum && start < end){
				sum(num,sum,start,end - 1,s);
			} else if (ss + num[end] < sum && start < end) {
				sum(num,sum,start + 1,end,s);
			} else {
				System.out.print(num[end]);
				sum(num, ss, 0, start >= end ? end - 1 : start, s - 1);
				if (start - 1 < end) {
					sum(num, sum, s - 2, end - 1, s);
				}
			}
		}
	}
	
	private void getGridData(){
		int i = 0 , j  = 0;
		int[] num = {1,2,3,4,5,6,7,8,9};
		Random rd = new Random();
		for (i = 0 ; i < m_board.length ; i ++){
			for (j = 0 ; j < m_board.length ; j ++){
				int n = rd.nextInt(num.length);
				m_board[i][j] = num[n];
				num[n] = num[num.length - 1];
				num = Arrays.copyOf(num,num.length - 1);
			}
		}
	}
	
	public void print(){
		for (int a = 0 ; a < m_board.length ; a ++){
			Arrays.stream(m_board[a]).forEach(System.out::print);
			System.out.println();
		}
	}
	
	//验证
	public boolean lin(){
		
		int sum;
		for (int a = 0 ; a < m_board.length ; a ++){
			sum = Arrays.stream(m_board[a]).sum();
			if (sum != 15){
				return false;
			}
		}
		
		
		for (int b = 0 ; b < m_board.length ; b ++) {
			sum = 0;
			for (int a = 0 ; a < m_board.length ; a ++){
				sum += m_board[a][b];
				if (sum != 15){
					return false;
				}
			}
		}
		
		sum = 0;
		for (int a = 0 ; a < m_board.length ; a ++){
			sum += m_board[a][a];
		}
		if (sum != 15){
			return false;
		}
		sum = 0;
		for (int a = 0 ; a < m_board.length ; a ++){
			sum += m_board[m_board.length - a][a];
		}
		if (sum != 15){
			return false;
		}
		return true;
	}
	
}

class test{
	static test test = new test();
	static{
		System.out.println("A");
	}
	{
		System.out.println("B");
	}
	
	public static void main(String[] args) {
		new test();
		int a = 10,b = 10;
		System.out.println("a + b : " + a + b);
		//System.out.println("a - b : " + a - b);
		System.out.println("a * b : " + a * b);
		System.out.println("a / b : " + a / b);
	}
}